home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / rTutors / part1 / rTutor.cc next >
Encoding:
C/C++ Source or Header  |  1990-04-23  |  2.6 KB  |  68 lines  |  [TEXT/pdos]

  1. /* PROGRAM R.Tutor (a tutorial for writing applications using resources)  */
  2. /* Part 1 - starting up & shutting down the tools from a ToolStartup List */
  3. /*          The list is kept in a resource */
  4.  
  5.  
  6. #include <types.h>     /* most common stuff */
  7. #include <INTMATH.h>   /* HiWord & LoWord come from here */
  8. #include <MEMORY.h>    /* used by MMStartUp call */
  9. #include <MISCTOOL.h>  /* SysBeep lives here */
  10. #include <LOCATOR.h>   /* StartupTools and ShutDownTools come from here */
  11.  
  12.  
  13. #define kStartStopID 1L  /* define constant for resource ID of StartStop list */
  14.  
  15.  
  16.  
  17. /* declare all of the global variables that we'll be using */
  18. unsigned gMyMemID;      /* holds the ID returned by MMStartup */
  19. Ref      gToolListRef;  /* the list of tools used to start and stop the tools */
  20. Boolean  gPunt;         /* TRUE if it's time to quit the app */
  21.  
  22.  
  23. /* ------------------------------------------------------------------------- */
  24. /* the following procedure is responsible for starting the tools (using the  */
  25. /* list in a resource) if the SartupTools call fails, then gPunt will        */
  26. /* contain "TRUE", so we can abort the app the global variable for this      */
  27. /* app's memory ID is acquired here as well.                                 */
  28.  
  29. do_init_rom() /* on the GS, start up the tools here */
  30. {
  31.  /* note, APW C's start.root file automatically buffers _ownerid for us, so  */
  32.  /* we can just grab it from there.  other languages may not do this, so you */
  33.  /* would have to replace the right-hand side of the line below with a call  */
  34.  /* to the memory manager (namely:  MMStartUp) to get your ID.               */
  35.  gMyMemID = _ownerid; /* find out what our memory id is & save it for later  */
  36.  
  37.  /* pay cloase attention!!!  Make sure kStartStopID is a long!!  Otherwise,  */
  38.  /* only a WORD will be pushed on the stack and the StartUpTools call will   */
  39.  /* fail! */
  40.  gToolListRef = StartUpTools(gMyMemID,refIsResource,kStartStopID);
  41.  
  42.  if (_toolErr == noError)
  43.   {
  44.    gPunt = FALSE; /* if there was no error, the app can continue starting up */
  45.   }
  46.   else
  47.   {
  48.   gPunt = TRUE; /* something went wrong, so set gPunt to indicate the failure */
  49.    }
  50. }
  51.  
  52.  
  53.  
  54. /* ------------------------------------------------------------------------- */
  55. /* the following procedure is the main application itself. */
  56.  
  57. main()
  58. {
  59.  do_init_rom(); /* get my memory id, start the tools, and set gPunt */
  60.  if (gPunt == FALSE)
  61.    {
  62.   SysBeep(); /* if tools started up ok, then beep three times and shut down */
  63.   SysBeep();
  64.   SysBeep();
  65.    }
  66.  ShutDownTools(refIsHandle,gToolListRef); /* shut down the tools & quit */
  67. } /* end of main program */
  68.